package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.dto.AllProductRequest;
import com.mall.shopping.dto.AllProductResponse;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 分页查询商品列表
 * @author 岳子昂
 * @date 2022-01-20 15:20
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/shopping")
public class GoodsController {

    @Reference(timeout = 10000,retries = 2, check = false)
    IProductService iProductService;


    /**
     * @description:
     * @param:
     * @return:
     * @author 岳子昂
     * @date: 2022-01-20 16:43
     */
    @RequestMapping("/goods")
    @Anoymous
    public ResponseData allProduct(AllProductRequest request){

        // 调用服务方法
        AllProductResponse response = iProductService.getAllProduct(request);

        // 判断解析结果
        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            return new ResponseUtil().setData(response.getAllProductDto());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }


}
